package com.cd.university.common.utils;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;

/**
 * @author 陈栋
 * @create 2021/10/26 17:15
 */

public class EncryptionAlgorithm {
    private static final String ALGORITHM_INFO = "PBEWithMD5AndDES";

    private static final String PASSWORD_INFO = "qwert12345";

    StringEncryptor stringEncryptor = new StandardPBEStringEncryptor();

    public static void main(String[] args) {
        StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
        //配置文件中配置如下的算法
        standardPBEStringEncryptor.setAlgorithm(ALGORITHM_INFO);
        //配置文件中配置的password
        standardPBEStringEncryptor.setPassword(PASSWORD_INFO);
        //要加密的文本
        String name = standardPBEStringEncryptor.encrypt("root");
        String password = standardPBEStringEncryptor.encrypt("root_my_root_666");
        String redisPassword = standardPBEStringEncryptor.encrypt("redis-password");
        //将加密的文本写到配置文件中
        System.out.println("root=" + name);
        System.out.println("password=" + password);
        System.out.println("redisPassword=" + redisPassword);

        //要解密的文本
//        String name2 = standardPBEStringEncryptor.decrypt("FarrmxSQX5uwtH/NZRxy+g==");
//        String password2 = standardPBEStringEncryptor.decrypt("vhiaYB1gl9zPj16yu7uMkA==");
//        String redisPassword2 = standardPBEStringEncryptor.decrypt("ZII7UphhbVuJ8c3oxPUeyw==");
        //解密后的文本
//        System.out.println("name2=" + name2);
//        System.out.println("password2=" + password2);
//        System.out.println("redisPassword2=" + redisPassword2);
    }


}
